package vip.xiaonuo.facedoor.modular.message;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.stereotype.Component;
import vip.xiaonuo.core.context.constant.ConstantContextHolder;
import vip.xiaonuo.facedoor.modular.message.domain.Message;

@Component
@Slf4j
public class SnowyMessageTemplate {

    public void sendLocalTransactionalMessage(Message message) {

        Boolean transactionalMessage = ConstantContextHolder.getSysConfig("TRANSACTIONAL_MESSAGE", Boolean.class, true);
        if (ObjectUtil.equal(transactionalMessage, Boolean.FALSE)) {
            return;
        }
        ReliableMessageSender bean;
        try {
            bean = SpringUtil.getBean(ReliableMessageSender.class);
        } catch (NoSuchBeanDefinitionException ignored) {
            log.error("未初始化 事务消息发送模块");
            return;
        }
        bean.send(message);
    }

}
